from django.conf import settings
from django.conf.urls.static import static
from django.urls import path, include
from spark import views
from rest_framework.routers import DefaultRouter
from spark.views import (
    join_task,
    task_students,
    set_group_leaders,
    TaskDetailView,
    UserProfileView,
    #SubtaskViewSet,
    UserJoinedTasksView,
    GetGroupMembersView,
    GetSubtasksByGroupView,
    task_students, get_user_by_username,
    deepseek_analyze_meeting_notes,
    GetUserGroupView,
    SubtaskViewSet,
    AllUsersView,
    RemindTaskView,
    SubmitTaskFileView,
    GetSubtaskReviewView,
    get_group_negotiate_scores,
    get_applicant_count,
    mark_applications_as_read,
    UpdateScoreView,
    GetMyScoreView,
    SubmitPeerReviewView,
    SubmitAppealView,
    Score_GetGroupMembersView,
    get_application_details, accept_application, GetLeaderDetailsView, SubmitApplicationView,
    generate_positions_and_survey,
    get_reference_positions,
    allocate_subtasks,
    check_and_update_task_statuses,
    accept_application,
    get_group_negotiate_scores,
    GetTeacherAppealsView,
    UpdateAppealStatusView,
    GetProgressTrackingView,
    get_application_details,
    FinalizeTaskScoresView,
    GetTeacherScoresView,
    GetFinishedTasksForTeacherView,
    GetTaskAnalysisDataView,
    AnalyzeTaskQualityView,
    CreateForumPostView,
    ForumPostsListView,
    ForumPostDetailView,
)

# 注册视图集
router = DefaultRouter()
router.register(r'api/subtasks', SubtaskViewSet, basename='subtask')

urlpatterns = [
    # 用户管理相关
    path('save', views.save, name='save_user'),
    path('remove/<int:_id>', views.remove, name='remove_user'),
    path('search', views.search, name='search_user'),

    # 用户注册、登录
    path('login', views.login, name='login'),
    path('register', views.register, name='register'),

    # 用户相关：确保这个路径在 `router.urls` 前面
    path('api/user/profile/', UserProfileView.as_view(), name='user-profile'),

    # 任务管理相关
    path('teacher/tasks/', views.teacher_task_list, name='teacher_task_list'),
    path('student/tasks/', views.student_task_list, name='student_task_list'),
    path('tasks/create/', views.create_task, name='create_task'),
    path('api/check-and-update-task-statuses/', check_and_update_task_statuses, name='check_and_update_task_statuses'),

    # 任务加入与学生列表
    path('tasks/<int:task_id>/join/', join_task, name='join_task'),
    path('tasks/<int:task_id>/students/', task_students, name='task_students'),

    # 小组管理相关：设置组长
    path('tasks/<int:task_id>/set-leaders/', set_group_leaders, name='set_group_leaders'),

    # 用户加入的任务列表
    path('api/user/joined-tasks/', UserJoinedTasksView.as_view(), name='user-joined-tasks'),

    # 任务详情
    path('api/show_task_detail/<int:task_id>/', TaskDetailView.as_view(), name='task-detail'),

    # 小组成员管理
    path('api/group/members/', GetGroupMembersView.as_view(), name='get-group-members'),

    # 根据用户id和taskid查询用户所在小组
    path('api/user/getgroupbytask/', GetUserGroupView.as_view(), name='get-user-group-by-task'),

    # 获取某小组的所有子任务
    path('api/subtasks/group/<int:group_id>/', GetSubtasksByGroupView.as_view(), name='get-subtasks-by-group'),
    #修改任务状态
    path('tasks/<int:task_id>/update-status/', views.update_task_status, name='update_task_status'),
    #查询任务组长清单
    path('tasks/<int:task_id>/leaders/', views.get_task_leaders, name='get_task_leaders'),
    path('api/task/remind/', RemindTaskView.as_view(), name='remind-task'),

    path('deepseek-analyze_meeting_notes', views.deepseek_analyze_meeting_notes, name='deepseek_analyze'),

    path('tasks/<int:task_id>/students/', task_students, name='task_students'),

    path('api/user/<str:username>/', get_user_by_username, name='get_user_by_username'),

    path('api/all-users/', AllUsersView.as_view(), name='all-users'),#在子任务中显示所有用户

    path('api/remind-task/', RemindTaskView.as_view(), name='remind-task'),
    #查看任务是否通过详情
    path('api/get-subtask-review/', GetSubtaskReviewView.as_view(), name='get-subtask-review'),

    path('api/submit-task-file/', SubmitTaskFileView.as_view(), name='submit-task-file'),

    path('api/get-group-negotiate-scores/', get_group_negotiate_scores, name='get-group-negotiate-scores'),

#读取申请数量
    path('tasks/<int:task_id>/applications/count', get_applicant_count, name='get_applicant_count'),
    #组长读取状态
    path('tasks/applications/mark-read/', views.mark_applications_as_read, name='mark_applications_as_read'),
    #更新分数
    path('api/update-score/', UpdateScoreView.as_view(), name='update-score'),

    path('api/my-score/', GetMyScoreView.as_view(), name='get-my-score'),
    path('api/peer-review/', SubmitPeerReviewView.as_view(), name='submit-peer-review'),
    path('api/appeal/', SubmitAppealView.as_view(), name='submit-appeal'),
    #根据task_id和group_id获取小组成员
    path('api/score/group_members/', Score_GetGroupMembersView.as_view(), name='score-get-group-members'),

    path('api/application-details/', get_application_details, name='get-application-details'),#获取申请详情
    path('api/accept-application/', accept_application, name='accept-application'),#接受申请

    path('api/leader-details/', GetLeaderDetailsView.as_view(), name='get-leader-details'),
    path('api/submit-application/', SubmitApplicationView.as_view(), name='submit-application'),

    path('api/generate-positions/', generate_positions_and_survey, name='generate-positions'),
    path('api/reference-positions/', get_reference_positions, name='get-reference-positions'),
    path('api/allocate-subtasks/', allocate_subtasks, name='allocate-subtasks'),

    path('api/get-teacher-appeals/', GetTeacherAppealsView.as_view(), name='get-teacher-appeals'),
    path('api/update-appeal-status/', UpdateAppealStatusView.as_view(), name='update-appeal-status'),

    path('api/progress-tracking/', GetProgressTrackingView.as_view(), name='progress-tracking'),

    path('api/finalize-task-scores/', FinalizeTaskScoresView.as_view(), name='finalize-task-scores'),
    path('api/get-teacher-scores/', GetTeacherScoresView.as_view(), name='get-teacher-scores'),

    path('api/get-finished-tasks/', GetFinishedTasksForTeacherView.as_view(), name='get-finished-tasks'),
    path('api/get-task-analysis-data/', GetTaskAnalysisDataView.as_view(), name='get-task-analysis-data'),
    path('api/analyze-task-quality/', AnalyzeTaskQualityView.as_view(), name='analyze-task-quality'),

    path('api/create-forum-post/', CreateForumPostView.as_view(), name='create-forum-post'),
    path('api/forum-posts/', ForumPostsListView.as_view(), name='forum-posts'),
    path('api/forum-post/<int:post_id>/', ForumPostDetailView.as_view(), name='forum-post-detail'),
    # 其他 URL...
    # 注册路由
    path('', include(router.urls)),  # 放置在最后，避免与其他路径冲突
]

# 静态文件和媒体文件的 URL 映射（仅在开发环境使用）
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)